using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Entities;
using BUS;
using Utility;

public partial class Admin_DealUpdate : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData();
            LoadDropDownList();
        }
    }
    private  void LoadDropDownList()
    {
        tbSanPhamCollection spCollection = tbSanPhamBUS.GetAll();
        ddl_sanpham.DataTextField = tbSanPhamColumns.TenSP.ToString();
        ddl_sanpham.DataValueField = tbSanPhamColumns.MaSP.ToString();
        ddl_sanpham.DataSource = spCollection;
        ddl_sanpham.DataBind();
        ddl_sanpham.Items.Insert(0, new ListItem("All", "0"));

        tbTinhTrangDealCollection ttdCollection = tbTinhTrangDealBUS.GetAll();
        ddl_tinhtrang.DataTextField = tbTinhTrangDealColumns.TenTTDEAL.ToString();
        ddl_tinhtrang.DataValueField = tbTinhTrangDealColumns.MaTTDEAL.ToString();
        ddl_tinhtrang.DataSource = ttdCollection;
        ddl_tinhtrang.DataBind();
        ddl_tinhtrang.Items.Insert(0, new ListItem("All", "0"));
    }
    private void  LoadData()
    {
        try
        {
        int iD=int.Parse (Request .QueryString ["iD"].ToString ());
        txt_madeal .Text =iD.ToString ();
        tbDeal deal=tbDealBUS .GetByID (iD);
        ddl_sanpham .SelectedValue =deal .SanPham .ToString ();
        ddl_tinhtrang .SelectedValue =deal .TinhTrang .ToString ();
        }
        catch
        {
            Response .Redirect ("~/Admin/DealDanhSach.aspx");
        }
    }
    protected void btn_sua_Click(object sender, EventArgs e)
    {
        try
        {
        int iD=int.Parse (Request .QueryString ["iD"].ToString ());
        tbDeal deal=tbDealBUS .GetByID (iD);
        deal .SanPham =int.Parse (ddl_sanpham .SelectedValue );
        deal .TinhTrang =int.Parse (ddl_tinhtrang .SelectedValue );
        tbDealBUS .Update (deal);
        Response .Redirect ("~/Admin/DealDanhSach.aspx");
    }
   catch
        {
            Response.Redirect("~/Admin/DealDanhSach.aspx");
        }

            Response.Redirect(Request.RawUrl);
    }
}